import socket

# 创建一个socket对象
sk = socket.socket()

# 绑定ip和端口
sk.bind(('127.0.0.1', 8848))

# 监听
sk.listen()

# 等待连接
while True:
    conn, addr = sk.accept()

    data = conn.recv(1024)
    url = data.decode('utf-8').split()[1]
    if url == '/index':
        ret = '欢迎进入红浪漫!'
    elif url == '/home':
        ret = '欢迎回家!'
    else:
        ret = '被查办了!'

    conn.send(b'HTTP/1.1 200 OK\r\ncontent-type: text/html; charset=utf-8\r\n\r\n')
    conn.send(ret.encode('utf-8'))

    conn.close()
